package org.zoomdev.zoom.dao;

import org.zoomdev.zoom.common.expression.Symbol;

public interface Query<T extends Query> extends Where<T> {


    T limit(int limit);

    T limit(int position, int limit);

    T orderBy(String key, Sort sort);

    T groupBy(String key);

    T having(String key, Symbol symbol, Object value);

    T join(String table, String on);


    T join(String table, String on, JoinType type);


    enum Sort {
        ASC("ASC"),
        DESC("DESC");

        private final String value;

        Sort(String value) {
            this.value = value;
        }

        public static Sort parse(String sort) {
            if (sort == null)
                return DESC;

            sort = sort.toUpperCase();

            for (Sort s : values()) {
                if (s.value.equals(sort)) {
                    return s;
                }
            }

            return DESC;
        }

        public String value() {
            return value;
        }

    }

    enum JoinType {
        INNER("INNER"),
        LEFT("LEFT"),
        RIGHT("RIGHT");

        private final String value;

        JoinType(String value) {
            this.value = value;
        }


        public String value() {
            return value;
        }
    }

}
